<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
          <a-form-item label="发生时间">
              <a-range-picker
              :allowClear="false"
              v-model="createTime"
              style="width: 100%"
              @change="createTimeChange"/>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExport" :disabled="isDisabledAuth('erpOilPayMoney:export')">导出</a-button>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
      </a-table>
    </div>
    <OilPayMoneyTransfer ref="exportMenu" @ok="exportOk"></OilPayMoneyTransfer>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import OilPayMoneyTransfer from './OilPayMoneyTransfer'
  import { downFile } from '@/api/manage'

  export default {
    name: 'ErpOilPayMoneyList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      OilPayMoneyTransfer
    },
    data () {
      return {
        description: '油补充值明细表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'姓名',
            align:"center",
            width:80,
            dataIndex: 'username_dictText',
          },
          {
            title:'所在部门',
            align:"center",
            width:80,
            dataIndex: 'deptId',
          },
          {
            title:'油卡卡号',
            align:"center",
            width:200,
            dataIndex: 'cardNumber_dictText',
          },
          {
            title:'充值金额',
            align:"center",
            width:100,
            dataIndex: 'payMoney',
          },
          {
            title:'固定车贴',
            align:"center",
            width:100,
            dataIndex: 'fixedCarSubsidy',
          },
          {
            title:'本月累计充值金额',
            align:"center",
            width:200,
            dataIndex: 'payMoneyAccumulative',
          },
          {
            title:'发生时间',
            align:"center",
            width:100,
            dataIndex: 'createTime',
          },

        ],
        url: {
          list: "/api/erp/modules/workbench/oilSubsidy/erpOilPayMoney/list",
          exportXlsUrl: "/api/erp/modules/workbench/oilSubsidy/erpOilPayMoney/exportXls",
        },
        dictOptions:{},
        superFieldList:[],
        createTime: [],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      customRow(record){},
      handleExport(){
      this.$refs.exportMenu.visible = true
      this.$refs.exportMenu.getOptions()
    },
    exportOk(val){
      const fileName = '油卡充值明细'
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      param.map = val
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            }),
            fileName + '.xls'
          )
        } else {
          let url = window.URL.createObjectURL(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            })
          )
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },
      createTimeChange(date, dateString) {
        this.$set(this.queryParam, 'createStartTime', dateString[0] + ' 00:00:00')
        this.$set(this.queryParam, 'createEndTime', dateString[1] + ' 23:59:59')
      },
      
      searchReset() {
        this.createTime = []
        this.queryParam = {}
        this.loadData(1)
    },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'username',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'deptId',text:'所在部门',dictCode:''})
        fieldList.push({type:'string',value:'cardNumber',text:'油卡卡号',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'payMoney',text:'充值金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'payMoneyAccumulative',text:'累计充值金额',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
